package com.zdy.today.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zdy.today.R;
import com.zdy.today.activity.MainActivity;

import java.util.ArrayList;
import java.util.List;


public class RecyclerWodeListAdapter extends RecyclerView.Adapter<RecyclerWodeListAdapter.ViewHolder> {
    private List<String> listBeen;
    private Context context;
    public RecyclerWodeListAdapter(Context context) {
        this.context=context;
        listBeen = new ArrayList<>();
        for (int i = 0; i < context.getResources().getStringArray(R.array.lg_wode_list_name).length; i++) {
            listBeen.add(context.getResources().getStringArray(R.array.lg_wode_list_name)[i]);
        }
    }


    // Provide a reference to the views for each data item
    // Complex data items may need more than one view per item, and
    // you provide access to all the views for a data item in a view holder
    public static class ViewHolder extends RecyclerView.ViewHolder {
        // each data item is just a string in this case
        public TextView lg_tv_name;
        public LinearLayout lg_ll_wode_item;

        public ViewHolder(View v) {
            super(v);
            lg_ll_wode_item = (LinearLayout) v.findViewById(R.id.lg_ll_wode_item);
            lg_tv_name = (TextView) v.findViewById(R.id.lg_tv_name);
        }
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // create a new view
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_item_wode, parent, false);
        // set the view's size, margins, paddings and layout parameters
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.lg_tv_name.setText(listBeen.get(position));
        holder.lg_ll_wode_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(MainActivity.getIntent(context,position));
            }
        });
    }

    @Override
    public int getItemCount() {
        return listBeen == null ? 0 : listBeen.size();
    }

}
